#!/bin/bash
mysql --user=root --password=project3 << EOF
CREATE DATABASE IF NOT EXISTS server1;
USE server1;
CREATE TABLE IF NOT EXISTS users (
  un char(30) NOT NULL PRIMARY KEY,
  pw text NOT NULL,
  phone char(9),
  email text,
  otppref char(1),
  is2fa char(1),
  isia char(1),
  isiaaccount char(1),
  hdvid char(40)
);

CREATE TABLE IF NOT EXISTS 2fa (
  sha1un char(40) PRIMARY KEY,
  code char(40) DEFAULT NULL,
  KEY code (code)
);

CREATE TABLE IF NOT EXISTS ia (
  s_code char(40) primary key,
  un char(30),
  FOREIGN KEY (un) references users(un) on delete cascade on update cascade,
  time bigint(20) unsigned
);

CREATE TABLE IF NOT EXISTS ia_cred (
  id char(40),
  secretkey char(40)
);

INSERT INTO users VALUES ('root', 'project3', null, 'nguyenk1125@gmail.com', 'e', 'n', 'n', 'n', null);
EOF
exit 0;
